package com.neu.ui;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.po.Doctor;
import com.neu.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/doctor")
@CrossOrigin(origins = "*")
public class DoctorlistController {

    @Autowired
    DoctorService doctorService;

    @GetMapping("/list/{doc_deptid}")
    public String list(@RequestParam(value="page",defaultValue="1") int page, @PathVariable("doc_deptid") int doc_deptid,String findname, Model m) {
        Map<String,Object> map = new HashMap<>();
        map.put("doc_deptid",doc_deptid);
        String where = "doc_deptid = #{m.doc_deptid}";
        if(findname!=null&&!findname.isEmpty()){
            map.put("doc_name", "%"+findname+"%");
            where+=" and doc_name like #{m.doc_name}";
        }
        where+=" ORDER BY doc_fee DESC";
        List<Doctor> list2 = doctorService.selectList(where,map);
        PageHelper.startPage(page,5);
        List<Doctor> list = doctorService.selectList(where,map);
        PageInfo<Doctor> pageInfo = new PageInfo<>(list);
        m.addAttribute("doc_list",pageInfo);
        m.addAttribute("list",list2);
        return "doctorlist";
    }
}
